| Conditions | 1 |
| Paths | 1 |
| Total Lines | 120 |
| Lines | 120 |
| Ratio | 100 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | View Code Duplication | var assert = require('chai').assert, |
|
| 4 | describe('SourceDescription', function(){ |
||
| 5 | |||
| 6 | var fullJSON = { |
||
| 7 | resourceType: 'http://some/type', |
||
| 8 | citations: [ |
||
| 9 | { |
||
| 10 | lang: 'en', |
||
| 11 | value: 'Long source citation' |
||
| 12 | } |
||
| 13 | ], |
||
| 14 | mediaType: 'book', |
||
| 15 | about: 'http://a/resource', |
||
| 16 | mediator: { |
||
| 17 | resource: 'http://mediator' |
||
| 18 | }, |
||
| 19 | sources: [ |
||
| 20 | { |
||
| 21 | description: 'http://source/reference' |
||
| 22 | } |
||
| 23 | ], |
||
| 24 | analysis: { |
||
| 25 | resource: 'http://analysis' |
||
| 26 | }, |
||
| 27 | componentOf: { |
||
| 28 | description: 'http://container' |
||
| 29 | }, |
||
| 30 | titles: [ |
||
| 31 | { |
||
| 32 | lang: 'en', |
||
| 33 | value: 'Title' |
||
| 34 | }, |
||
| 35 | { |
||
| 36 | lang: 'es', |
||
| 37 | value: 'Titulo' |
||
| 38 | } |
||
| 39 | ], |
||
| 40 | notes: [ |
||
| 41 | { |
||
| 42 | subject: 'Note', |
||
| 43 | text: 'Some note text' |
||
| 44 | } |
||
| 45 | ], |
||
| 46 | attribution: { |
||
| 47 | created: 1234578129 |
||
| 48 | }, |
||
| 49 | rights: [ |
||
| 50 | { |
||
| 51 | resource: 'https://some/right' |
||
| 52 | } |
||
| 53 | ], |
||
| 54 | coverage: { |
||
| 55 | temporal: { |
||
| 56 | formal: '+2015' |
||
| 57 | }, |
||
| 58 | spatial: { |
||
| 59 | original: 'A place' |
||
| 60 | } |
||
| 61 | }, |
||
| 62 | descriptions: [ |
||
| 63 | { |
||
| 64 | value: 'A description' |
||
| 65 | } |
||
| 66 | ], |
||
| 67 | identifiers: { |
||
| 68 | $: 'identifier' |
||
| 69 | }, |
||
| 70 | created: 1000000, |
||
| 71 | modified: 11111111, |
||
| 72 | repository: { |
||
| 73 | resource: 'http://repository' |
||
| 74 | }, |
||
| 75 | titleLabel: 'Title', |
||
| 76 | sortKey: '123456', |
||
| 77 | descriptorRef: '#dref' |
||
| 78 | }; |
||
| 79 | |||
| 80 | it('Create with JSON', function(){ |
||
| 81 | var description = GedcomX.SourceDescription(fullJSON); |
||
| 82 | tests(description); |
||
| 83 | }); |
||
| 84 | |||
| 85 | it('Build', function(){ |
||
| 86 | var description = GedcomX.SourceDescription() |
||
| 87 | .setResourceType('http://some/type') |
||
| 88 | .addCitation(GedcomX.SourceCitation().setLang('en').setValue('Long source citation')) |
||
| 89 | .setMediaType('book') |
||
| 90 | .setAbout('http://a/resource') |
||
| 91 | .setMediator(GedcomX.ResourceReference().setResource('http://mediator')) |
||
| 92 | .addSource(GedcomX.SourceReference().setDescription('http://source/reference')) |
||
| 93 | .setAnalysis(GedcomX.ResourceReference().setResource('http://analysis')) |
||
| 94 | .setComponentOf(GedcomX.SourceReference().setDescription('http://container')) |
||
| 95 | .addTitle(GedcomX.TextValue().setLang('en').setValue('Title')) |
||
| 96 | .addTitle(GedcomX.TextValue().setLang('es').setValue('Titulo')) |
||
| 97 | .addNote(GedcomX.Note().setSubject('Note').setText('Some note text')) |
||
| 98 | .setAttribution(GedcomX.Attribution().setCreated(1234578129)) |
||
| 99 | .addRight(GedcomX.ResourceReference().setResource('https://some/right')) |
||
| 100 | .setTitleLabel('Title') |
||
| 101 | .setSortKey('123456') |
||
| 102 | .setDescriptorRef('#dref') |
||
| 103 | .setCoverage( |
||
| 104 | GedcomX.Coverage() |
||
| 105 | .setTemporal(GedcomX.Date().setFormal('+2015')) |
||
| 106 | .setSpatial(GedcomX.PlaceReference().setOriginal('A place')) |
||
| 107 | ) |
||
| 108 | .addDescription(GedcomX.TextValue().setValue('A description')) |
||
| 109 | .setIdentifiers(GedcomX.Identifiers({ |
||
| 110 | $: 'identifier' |
||
| 111 | })) |
||
| 112 | .setCreated(1000000) |
||
| 113 | .setModified(11111111) |
||
| 114 | .setRepository(GedcomX.ResourceReference().setResource('http://repository')); |
||
| 115 | tests(description); |
||
| 116 | }); |
||
| 117 | |||
| 118 | it('toJSON', function(){ |
||
| 119 | var description = GedcomX.SourceDescription(fullJSON); |
||
| 120 | assert.deepEqual(description.toJSON(), fullJSON); |
||
| 121 | }); |
||
| 122 | |||
| 123 | }); |
||
| 124 | |||
| 159 | } |